package com.example.demo.mapper;

import com.example.demo.entity.User;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface UserMapper {

    @Select("select * from user")
    List<User> findAll();

    @Update("INSERT INTO `user`(`name`, `password`, `time`, `progress`, `path`) VALUES (#{name}, #{password},  #{time}, #{progress}, #{path});")
    @Transactional
    void save(User user);

    @Select("select * from user where name = #{arg0} and time = #{arg1}")
    User findByName(String name,String time);

    @Select("select id from user where name = #{arg0} and time = #{arg1}")
    Integer findIdByName(String name,String time);

    @Update("update user set name=#{name}, password = #{password}, time=#{time}, progress=#{progress}, path=#{path} where id = #{id}")
    @Transactional
    void updateById(User user);

    @Update("update user set progress=#{progress} where id = #{id}")
    @Transactional
    void updateProById(User user);

    //    @Select("select id from user order by id desc limit 1")
//    int saveId();
//
//    @Select("select time from user order by id desc limit 1")
//    String saveTime();
//
//    @Delete("delete from user where id = #{id}")
//    void deleteById(Long id);
//
//    @Select("select * from user where id = #{id}")
//    User findById(Long id);

//    @Select("select * from user limit #{offset},#{pageSize}")
//    List<User> findByPage(Integer offset, Integer pageSize);

//    @Select("select count(id) from user")
//    Integer countUser();
}
